<template>
  {{ currentTag }}
  <a-tag v-if="currentTag" :color="color[value]">{{currentTag.label}}</a-tag>
  <span v-else>-</span>
</template>
<script setup name="dic-tag">
import { UserStore } from "@/store/modules/user";
import {computed} from "vue"
import { get ,isArray,find} from "lodash"
import { useI18n } from "vue-i18n";
const { locale } = useI18n({inheritLocale: true,useScope: 'local'})
// {locale: "en" | "ch"}
import { GlobalStore } from "@/store/modules/global";
const props = defineProps({
  value:{
    type:[String,Number,Boolean],
    default:''
  },
  type:{
    type:[String,Array],
    default:''
  }
})

const globalStore = GlobalStore()
const color = {
  1:'#2db7f5',
  2:'#87d068', 
  9: globalStore.$state.config.themePrimary,
  '-1':'#f50'
}

const userStore = UserStore()

const dicMap = computed(()=>{
  return userStore.getDic
})

const currentDicList = computed(()=>{
  if(isArray(props.type)){
    return props.type
  }
  return get(dicMap.value,props.type,[])
})

const currentTag = computed(()=>{  
  
  if(isArray(currentDicList.value)){

    const item = find(currentDicList.value,['value',props.value])
    console.log('item',item);
    if(item && item.locale){
      item.label = item.locale[locale.value] 
    }
    return item
  }
  return {}
})



</script>
<style lang="less" scoped>

  
</style>